﻿/// <reference path="../../Common/MyJS/MyWebsite.js" />

function getMainPageTabCtrl() {
    /// <summary>获取页面主题部分，tab控件</summary>
    return $("#div_main");
};

function getTabByTitle(sTitle) {
    /// <summary>根据tab标题获取tab对象</summary>
    /// <param name="sTitle" type="String">页面的标题</param>
    var oTabCtrl = getMainPageTabCtrl();
    var oTab = oTabCtrl.tabs("getTab", sTitle);
    return oTab;
};

function getActiveTabTitle() {
    /// <summary>获取当前选中的选项卡的标题</summary>
    var oTabCtrl = getMainPageTabCtrl();
    var oTab = oTabCtrl.tabs('getSelected');
    if (oTab) return oTab.panel('options').title;
    return "";
};

function addPage(sUrl, sTitle, bNoNeedLoading, sTabConfig) {
    /// <summary>打开一个新的页面</summary>
    /// <param name="sUrl" type="String">页面的Url路径（不能为空）</param>
    /// <param name="sTitle" type="String">打开页面的标题</param>
    /// <param name="bNoNeedLoading" type="Boolean">是否需要加载中的页面，默认false，表示需要</param>
    /// <param name="sTabConfig" type="JSONObject">tab页面的其他配置参数，必须是json数据</param>
    if (!sUrl) return;
    var oTabCtrl = getMainPageTabCtrl();
    var oTab = oTabCtrl.tabs("getTab", sTitle);
    if (oTab) {
        oTabCtrl.select(oTab);
    }
    else {
        if (!bNoNeedLoading) {
            var sLoading = MyWebsite.getServerAddr() + "MISCommon/Pages/Loading.aspx";
            sUrl = MyString.urlAppend(sLoading, "goto=" + MyWebsite.encodeUrlParam(sUrl));
        }
        var sContent = '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + sUrl + '" />';
        var oConfig = { content: sContent, title: sTitle, closable: true };
        if (sTabConfig) {
            $.extend(true, oConfig, $.parseJSON(sTabConfig));
        }
        oTabCtrl.tabs("add", oConfig);
    }
};